home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 28.6 KB | 1,050 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UDebug.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- // MacApp
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __USEGMENTS__
- #include "USegments.h"
- #endif
-
- #ifndef __UTHEDEBUGGER__
- #include "UTheDebugger.h"
- #endif
-
- // Toolbox
-
- #if qDebug || qTheDebugger
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
- #endif
-
- #if qDebug && qSegments
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
- #endif
-
- #ifndef SYMANTEC_CPLUS
- #ifndef __UNMANGLER__
- #include "Unmangler.h"
- #endif
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- // Apple Specials
-
- #if qDebug && !qPowerPC
- #ifndef __DISASMLOOKUP__
- #include "DisAsmLookup.h"
- #endif
- #endif
-
- #ifndef __MWERKS__
- #ifndef __FCNTL__
- #include "fcntl.h"
- #endif
-
- #ifndef __IOCTL__
- #include "ioctl.h"
- #endif
- #endif
-
- // Voodoo Monkey
-
- #ifndef __NUBINSPECTORHOOKS__
- #include "NubInspectorHooks.h"
- #endif
-
- // Metrowerks
-
- #ifdef __MWERKS__
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
- #endif
-
- #if (qDebug || qTheDebugger) && defined(__MWERKS__)
- #ifndef __CWDEBUG__
- #include "CWDebug.h"
- #endif
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Procedure pointer typedefs
- //----------------------------------------------------------------------------------------
-
- #if qDebug || qTheDebugger
-
- typedef long(*GetProcPtr)(Ptr buffer, long count);
- typedef void(*PutProcPtr)(Ptr buffer, long count);
-
- #endif // qDebug || qTheDebugger
-
- //----------------------------------------------------------------------------------------
- // struct IOPort: Used to hook MPW StdErr, StdIn, StdOut
- //----------------------------------------------------------------------------------------
-
- #if qDebug || qTheDebugger
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
- struct IOPort
- {
- unsigned char filler[12];
- long count;
- Ptr bufp;
- };
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- #endif // qDebug || qTheDebugger
-
- Boolean gHighLevelDebuggerRunning; // True if we were able to launch
- // SourceBug, Sade OR Jasik running
-
-
- //----------------------------------------------------------------------------------------
- // Global variable definitions.
- //----------------------------------------------------------------------------------------
-
- #if qDebug
-
- Boolean gUserFlag1;
-
- Boolean gUserFlag2;
-
- Boolean gUserFlag3;
-
- Boolean gAssumeFocused = TRUE; // make TView::AssumeFocused actually
- // check focus.
-
- Boolean gDebugPrinting;
-
- Boolean gIntenseDebugging;
-
- Boolean gReportEvent;
-
- Boolean gReportMenuChoices;
-
- Boolean gShowCursorRegion;
-
- Boolean gShowHelpRegion;
-
- Boolean gShowInvalidations; // make TWindow::InvalidVRect
- // graphically show the invalidation
- // region
-
- Boolean gShowSleepRegion;
-
- Boolean gMemMgtBreak;
-
- Boolean gRsrcReport;
- // Report resource maximums to the debugger window.
-
- Boolean gSegReport;
- // Report segment loadings to the debugger window.
-
- //Boolean gMastReport = TRUE;
-
- short gCurrentDebugger = kxNoDebugger; // constants defined in CWDebug.h
-
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // Static variable definitions.
- //----------------------------------------------------------------------------------------
-
- #if qDebug || qTheDebugger
- #if !(THINK_CPLUS || SYMANTEC_CPLUS) && !defined(__MWERKS__)
-
- static GetProcPtr pGetProc; // Address of the Proc to Handle
- // Read requests Function
- // DEVGETTEXT(textBuf: Ptr, byteCount:
- // longint): longint;
-
- static PutProcPtr pPutProc; // Address of the Proc to Handle
- // WriteLn requests Procedure
- // DEVPUTTEXT(textBuf: Ptr, byteCount:
- // longint);
- #endif // !(THINK_CPLUS || SYMANTEC_CPLUS) && !defined(__MWERKS__)
-
- static Boolean pUDebugInitialized; // True if InitUDebug has been called
-
- #endif // (qDebug || qTheDebugger)
-
- #if (qDebug || qTheDebugger)
-
- static ProcessSerialNumber pDebuggerProcess; // The process number of the high level
- // debugger if there is one.
-
- #endif // qDebug
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
-
- #if qDebug || qTheDebugger
-
- #if qDebug
- static void FindHighLevelDebugger();
- static Boolean FindDebuggerProcess(OSType sig, short debugger);
- #endif
-
- static void InstallWriteLnHook();
-
- #if !(THINK_CPLUS || SYMANTEC_CPLUS) && !defined(__MWERKS__)
- static GetProcPtr SetGetProc(GetProcPtr theGetProc);
- static PutProcPtr SetPutProc(PutProcPtr thePutProc);
- static long DebugReadLn(Ptr buffer, long byteCount);
- #endif // !(THINK_CPLUS || SYMANTEC_CPLUS) && !defined(__MWERKS__)
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // External function definitions (no mangling).
- //----------------------------------------------------------------------------------------
-
- #if !(THINK_CPLUS || SYMANTEC_CPLUS) && !defined(__MWERKS__)
- extern "C"
- {
- extern long DevClose(long iop);
- extern long DevIoctl(long iop,
- long command,
- void* arg);
- extern long DevFAccess(char* fName,
- long command,
- void* arg);
- extern long DevRead(long iop);
- extern long DevWrite(long iop);
-
- extern long _addDevHandler(long slot,
- long dvName,
- void* dvFAccess,
- void* dvClose,
- void* dvRead,
- void* dvWrite,
- void* dvIoctl);
- }
- #endif // !(THINK_CPLUS || SYMANTEC_CPLUS) && !defined(__MWERKS__)
-
- #if qDebug
-
- //========================================================================================
- // CLASS CStackFrame
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::CStackFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- CStackFrame::CStackFrame(void* framePtr)
- {
- fFramePtr = (ptrdiff_t) framePtr;
- } // CStackFrame::CStackFrame
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::CStackFrame:
- //----------------------------------------------------------------------------------------
- CStackFrame::CStackFrame(void)
- {
- fFramePtr = (ptrdiff_t) 1;
- } // CStackFrame::CStackFrame
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::CStackFrame:
- //----------------------------------------------------------------------------------------
- CStackFrame::CStackFrame(ptrdiff_t framePtr)
- {
- fFramePtr = framePtr;
- } // CStackFrame::CStackFrame
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::GetCallersStackFrame:
- //----------------------------------------------------------------------------------------
- CStackFrame CStackFrame::GetCallersStackFrame() const
- {
- return CStackFrame(*((ptrdiff_t *) fFramePtr));
- } // CStackFrame::GetCallersStackFrame
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::GetReturnAddress:
- //----------------------------------------------------------------------------------------
- void* CStackFrame::GetReturnAddress() const
- {
- return *(void **) (fFramePtr + 4);
- } // CStackFrame::GetReturnAddress
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::GetStackFramePtr:
- //----------------------------------------------------------------------------------------
- const ptrdiff_t CStackFrame::GetStackFramePtr() const
- {
- return fFramePtr;
- } // CStackFrame::GetStackFramePtr
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::GetParametersPtr:
- //----------------------------------------------------------------------------------------
- const ptrdiff_t CStackFrame::GetParametersPtr() const
- {
- return fFramePtr + 8;
- } // CStackFrame::GetParametersPtr
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::GetParameterWord:
- //----------------------------------------------------------------------------------------
- const short& CStackFrame::GetParameterWord(short nthWord) const
- {
- return *((short *) (fFramePtr + 8 + (nthWord - 1) * sizeof(short)));
- } // CStackFrame::GetParameterWord
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::GetParameterDoubleWord:
- //----------------------------------------------------------------------------------------
- const long& CStackFrame::GetParameterDoubleWord(short nthDoubleWord) const
- {
- return *((long *) (fFramePtr + 8 + (nthDoubleWord - 1) * sizeof(long)));
- } // CStackFrame::GetParameterDoubleWord
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::GetLocalWord:
- //----------------------------------------------------------------------------------------
- const short& CStackFrame::GetLocalWord(short nthWord) const
- {
- return *((short *) (fFramePtr - nthWord * sizeof(short)));
- } // CStackFrame::GetLocalWord
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::GetLocalDoubleWord:
- //----------------------------------------------------------------------------------------
- const long& CStackFrame::GetLocalDoubleWord(short nthDoubleWord) const
- {
- return *((long *) (fFramePtr - nthDoubleWord * sizeof(long)));
- } // CStackFrame::GetLocalDoubleWord
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::LooksValid:
- //----------------------------------------------------------------------------------------
- Boolean CStackFrame::LooksValid() const
- {
- #if qPowerPC
- #define GetCurStackTop() 0
- #endif
-
- return !odd((long) fFramePtr) &&
- fFramePtr < (ptrdiff_t) LMGetCurStackBase() &&
- fFramePtr > (ptrdiff_t) GetCurStackTop();
-
- } // CStackFrame::LooksValid
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::operator==:
- //----------------------------------------------------------------------------------------
- Boolean CStackFrame::operator==(const CStackFrame& stackFrame) const
- {
- return fFramePtr == stackFrame.fFramePtr;
- } // CStackFrame::operator==
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrame::operator!=:
- //----------------------------------------------------------------------------------------
- Boolean CStackFrame::operator!=(const CStackFrame& stackFrame) const
- {
- return fFramePtr != stackFrame.fFramePtr;
- } // CStackFrame::operator!=
-
-
-
- //========================================================================================
- // CLASS CStackFrameIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CIterator
-
- //----------------------------------------------------------------------------------------
- // CStackFrameIterator::CStackFrameIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- CStackFrameIterator::CStackFrameIterator(CStackFrame topFrame)
- {
- fTopFrame = topFrame;
- this->Reset();
- } // CStackFrameIterator::CStackFrameIterator
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrameIterator::More:
- //----------------------------------------------------------------------------------------
- Boolean CStackFrameIterator::More()
- {
- return fCurrentFrame.LooksValid();
- } // CStackFrameIterator::More
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrameIterator::Reset:
- //----------------------------------------------------------------------------------------
- void CStackFrameIterator::Reset()
- {
- fCurrentFrame = this->FirstFrame();
- } // CStackFrameIterator::Reset
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrameIterator::FirstFrame:
- //----------------------------------------------------------------------------------------
- CStackFrame CStackFrameIterator::FirstFrame()
- {
- return fTopFrame;
- } // CStackFrameIterator::FirstFrame
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrameIterator::NextFrame:
- //----------------------------------------------------------------------------------------
- CStackFrame CStackFrameIterator::NextFrame()
- {
- this->Advance();
- return fCurrentFrame;
- } // CStackFrameIterator::NextFrame
-
-
- //----------------------------------------------------------------------------------------
- // CStackFrameIterator::Advance:
- //----------------------------------------------------------------------------------------
- void CStackFrameIterator::Advance()
- {
- if (this->More())
- fCurrentFrame = fCurrentFrame.GetCallersStackFrame();
- } // CStackFrameIterator::Advance
-
-
- #endif // qDebug
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUDebug: essential initialization (segTable, nonRes left in for compatibility (2.0)
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- #if qDebug || qTheDebugger
-
- void InitUDebug()
- {
- if ( TheDbgr_IsInstalled() )
- {
- #if qTheDebugger
- gHighLevelDebuggerRunning = TRUE;
- InstallWriteLnHook();
- TheDbgr_Init_Ext_Dbgr(); // Initialize Hooks for Jasik
- gCurrentDebugger = kxJasik;
- #endif
- }
- #if qDebug
- else
- {
- gHighLevelDebuggerRunning = FALSE;
- FindHighLevelDebugger();
- // MA_REGISTER_CLASS(TDebugFlagsView); // Registered in IApplication
- InstallWriteLnHook();
- }
- #endif
-
- pUDebugInitialized = TRUE;
- } // InitUDebug
-
- #endif // qDebug || qTheDebugger
-
- //----------------------------------------------------------------------------------------
- // FindHighLevelDebugger:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- #if qDebug
-
- void FindHighLevelDebugger()
- {
- // First, check to see if the NutraBug Nub exists.
- if (NubIsInstalled())
- gHighLevelDebuggerRunning = TRUE;
-
- // Check to see if one of the high level debuggers are running (SourceBug or Sade).
- // If so then we will send debug output to it.
- Boolean found = FindDebuggerProcess('Objr', kxSourceBug); // Is SourceBug running?
- if (!found)
- found = FindDebuggerProcess('sade', kxSade); // Is Sade running?
- if (!found)
- found = FindDebuggerProcess('MWDB', kxMWDebug68K); // Is MWDebug68K running?
- if (!found)
- found = FindDebuggerProcess('MPDB', kxMWDebugPPC); // Is MWDebugPPC running?
- if (!found)
- found = FindDebuggerProcess('R2Db', kxR2DbPPC); // Is Apple's R2DbPPC running?
- if (!found)
- found = FindDebuggerProcess('Alar', kxR2Db68K); // Is Apple's R2Db68K running?
- if (!found)
- found = FindDebuggerProcess('sDeb', kxVooDoo); // Is VooDooMonkey running?
-
- gHighLevelDebuggerRunning = found;
- if (!found)
- gCurrentDebugger = kxNoDebugger;
- }
-
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // FindDebuggerProcess
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- #if qDebug
-
- Boolean FindDebuggerProcess(OSType sig, short debugger)
- {
- ProcessSerialNumber psn;
- OSErr err = FindProcessBySignature(sig, psn, NULL);
- Boolean found = (err == noErr);
- if (found)
- {
- gCurrentDebugger = debugger;
- pDebuggerProcess = psn;
- }
- return found;
- }
-
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // DebugCanReadLn: Returns true if you can readln to the user
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- #if qDebug
-
- Boolean DebugCanReadLn()
- {
- return FALSE;
- } // DebugCanReadLn
-
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // DebugCanWriteLn: Returns true if you can writeln to the user
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- #if qDebug
-
- Boolean DebugCanWriteLn()
- {
- return pUDebugInitialized;
- } // DebugCanWriteLn
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // EachFrameDo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- #if qDebug
-
- void EachFrameDo(CStackFrame baseFrame,
- DoToFrameType DoToFrame,
- void* yourDataPtr)
- {
- CStackFrameIterator iter(baseFrame);
- CStackFrame frame;
-
- for (frame = iter.FirstFrame(); iter.More(); frame = iter.NextFrame())
- {
- DoToFrame(frame, yourDataPtr);
- }
- } // EachFrameDo
-
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // GetCallersMethodName:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- #if qDebug
-
- void GetCallersMethodName(MAName& s)
- {
- #if qPowerPC
- s = "PowerPC";
- #else
- CStackFrame stackFrame(GetCurStackFramePtr());
- GetMethodName(stackFrame.GetReturnAddress(), s); // report about our caller"s caller
- #endif
- } // GetCallersMethodName
-
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // GetMethodName: GetMethodName returns the name of the method (or procedure) in which pc
- // points.
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- #if qDebug
-
- void GetMethodName(void* pc, MAName& s)
- {
- MAName discardStr;
- GetProcName(pc, discardStr, s);
- } // GetMethodName
-
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // GetProcName: GetProcName returns the name of the procedure or function in which pc
- // points. If it is in a method, then it return"s the name of the method"s class in
- // className.
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- #if qDebug
-
- void GetProcName(void*
- #if !qPowerPC
- pc
- #endif
- , ClassName& className, MAName& procName)
- {
- #if !qPowerPC
- if (pc != NULL && !odd((long) pc))
- {
- void* nextPC;
- CStr255 localProcName;
-
- Ptr limit = (Ptr) ((ptrdiff_t) pc + 32767);
- //••• SRF Codewarrior 8 doesn't have a CFM68K stub that includes endOfModule
- #if !(qModelCFM && defined(__MWERKS__))
- while (!endOfModule(pc, limit, (char *) &localProcName, &nextPC))
- {
- if (pc >= limit)
- {
- className.Empty();
- procName.Empty();
- localProcName.Empty();
- return;
- }
- else
- pc = (void *) ((ptrdiff_t) pc + 2);
- }
- #endif
- char cProcName[256];
-
- if (unmangle(cProcName, (char *) &localProcName, 255) < 1)
- procName = localProcName;
- else
- procName = cProcName;
-
- short index = procName.Pos(".");
- if (index != 0)
- className = procName.Copy(1, index - 1);
- else
- className.Empty();
- }
- else
- #endif
- {
- className.Empty();
- procName.Empty();
- }
- } // GetProcName
-
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // ShowSegments:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- #if qDebug
-
- void ShowSegments()
- {
- #if qSegments
- // Show segment information.
-
- fprintf(stderr, "[•=resident L=loaded U=unloaded -=purged], H=high water, E=ever loaded\n");
-
- long codeRes = 0; // counts size of code segments
- long i = 0;
- for (CCodeSegment * codeSegment = gCodeSegs; codeSegment; codeSegment = codeSegment->fNextCodeSegment)
- {
- ++i;
- Handle seg = codeSegment->fCodeSeg;
- if (seg)
- {
- short id;
- CStr255 name;
- ResType t;
-
- GetResInfo(seg, &id, &t, name);
-
- WritePtr((long) seg);
- // if (seg == NULL)
- // fprintf(stderr, "NULL");
- // else
- // fprintf(stderr, "%X", (long) seg);
-
- fprintf(stderr, " Seg#:%3d ", id);
-
- if (codeSegment->fResidentSeg)
- fprintf(stderr, "• ");
- else if (IsHandlePurged(seg))
- fprintf(stderr, "- ");
- else if (codeSegment->fSegLoaderLoaded)
- fprintf(stderr, "L ");
- else
- fprintf(stderr, "U ");
-
- if (codeSegment->fHighWater)
- fprintf(stderr, "H ");
- else
- fprintf(stderr, "- ");
-
- if (codeSegment->fEverLoaded)
- fprintf(stderr, "E ");
- else
- fprintf(stderr, "- ");
-
- fprintf(stderr, " %s ", (const char *) name);
-
- fprintf(stderr, "%ld bytes\n", codeSegment->GetSize());
-
- codeRes += codeSegment->fSegSize + 8;
- }
- }
-
- fprintf(stderr, "\n");
- fprintf(stderr, "Total # segments = %d \n" , i);
- fprintf(stderr, "Total loaded code = %ld\n", codeRes);
-
- long lockedSpace = CGrowZoneHook::TotalTempSize(TRUE);
- long totalSpace = CGrowZoneHook::TotalTempSize(FALSE);
- fprintf(stderr," Current temp space: locked = %ld, unlocked = %ld, total = %ld\n",
- lockedSpace, totalSpace - lockedSpace, totalSpace);
- #endif
- } // ShowSegments
-
- #endif // qDebug
-
- //========================================================================================
- // Debug output with Apple's runtime library
- //========================================================================================
-
- #if qDebug || qTheDebugger
- #if !(THINK_CPLUS || SYMANTEC_CPLUS) && !defined(__MWERKS__)
-
- //----------------------------------------------------------------------------------------
- // DevFAccess:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevFAccess(char* fName, long command, void* /* arg */)
- {
- const Boolean CaseSensitive = TRUE;
- const Boolean DiacritSensitive = TRUE;
- const CStr255 fileName = fName;
-
- const CStr255 kConsoleName = "dev:console"; // console device name
- if (EqualString(fileName, kConsoleName, !CaseSensitive, DiacritSensitive))
- switch (command)
- {
- case F_OPEN:
- return 0;
-
- default:
- return -1;
- }
- else
- return -1;
- } // DevFAccess
-
- //----------------------------------------------------------------------------------------
- // DevClose:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevClose(long)
- {
- return 0;
- } // DevClose
-
- //----------------------------------------------------------------------------------------
- // DevRead:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevRead(long iop)
- {
- IOPort * iopPtr = (IOPort *)iop;
- long bytesRead;
-
- bytesRead = pGetProc(iopPtr->bufp, iopPtr->count);
- iopPtr->bufp += bytesRead;
- iopPtr->count -= bytesRead;
- return 0;
- } // DevRead
-
- //----------------------------------------------------------------------------------------
- // DevWrite:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevWrite(long iop)
- {
- IOPort * iopPtr = (IOPort *)iop;
-
- pPutProc(iopPtr->bufp, iopPtr->count);
- iopPtr->count = 0;
- return 0;
- } // DevWrite
-
- //----------------------------------------------------------------------------------------
- // DevIoctl:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevIoctl(long /* iop */,
- long command,
- void* /* arg */)
- {
- switch (command)
- {
- case FIOINTERACTIVE:
- case TIOFLUSH:
- return 0;
-
- default:
- return -1;
- }
- } // DevIoctl
-
- //----------------------------------------------------------------------------------------
- // SetGetProc:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- GetProcPtr SetGetProc(GetProcPtr theGetProc)
- {
- GetProcPtr returnProc = pGetProc;
- pGetProc = theGetProc;
- return returnProc;
- } // SetGetProc
-
- //----------------------------------------------------------------------------------------
- // SetPutProc:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- PutProcPtr SetPutProc(PutProcPtr thePutProc)
- {
- PutProcPtr returnProc = pPutProc;
- pPutProc = thePutProc;
- return returnProc;
- } // SetPutProc
-
- //----------------------------------------------------------------------------------------
- // DebugReadLn:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- long DebugReadLn(Ptr /*buffer*/, long /*byteCount*/)
- {
- return 0;
- } // DebugReadLn
-
- #endif // !(THINK_CPLUS || SYMANTEC_CPLUS) && !defined(__MWERKS__)
- #endif // qDebug || qTheDebugger
-
- //----------------------------------------------------------------------------------------
- // ConfirmHighLevelDebugger:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- #if qDebug || qTheDebugger
-
- void ConfirmHighLevelDebugger()
- {
- #if qTheDebugger
- if (gExtDbgr_Info.isBeingDebugged || TheDbgr_IsInstalled()) // keeps MMU from complaining
- gHighLevelDebuggerRunning = TRUE;
- #endif // qTheDebugger
- #if qDebug
- #if qTheDebugger
- else
- #endif // qTheDebugger
- if (gHighLevelDebuggerRunning)
- {
- if (NubIsInstalled())
- gHighLevelDebuggerRunning = TRUE;
-
- OSErr err;
- ProcessInfoRec processInfo;
-
- // Check to see if the high level debugger is still running. The user could have
- // closed the application. If it is no longer running then just quit sending
- // output to the debugger.
-
- processInfo.processInfoLength = sizeof(ProcessInfoRec);
- processInfo.processName = NULL;
- processInfo.processAppSpec = NULL;
-
- err = GetProcessInformation(&pDebuggerProcess, &processInfo);
- if (err != noErr)
- {
- gHighLevelDebuggerRunning = FALSE;
- gCurrentDebugger = kxNoDebugger;
- }
- }
- #endif // qDebug
- } // ConfirmHighLevelDebugger
-
- #endif // qDebug || qTheDebugger
-
- //----------------------------------------------------------------------------------------
- // DebugWriteLnHook:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- #if qDebug || qTheDebugger
-
- void DebugWriteLnHook(Ptr textBuf, long byteCount)
- {
- ConfirmHighLevelDebugger();
-
- CStr255 debugStr;
- Ptr p = textBuf;
- while (byteCount > 0)
- {
- long len = Min(byteCount, 250);
- int i = 0;
- char* d = ((char*)&debugStr) + 1;
- while (i < len)
- {
- char c = *p++;
- *d++ = c;
- if ((c == '\r') || (c == '\n'))
- {
- len = i + 1;
- break;
- }
- i++;
- }
- debugStr.Length() = (unsigned char) i;
-
- if ((gCurrentDebugger == kxSourceBug) || (gCurrentDebugger == kxVooDoo) ||
- (gCurrentDebugger == kxSade))
- {
- debugStr += '\n';
- SysBreakFunc(debugStr);
- }
- else
- #if qTheDebugger
- if (gExtDbgr_Info.isBeingDebugged || TheDbgr_IsInstalled())
- {
- debugStr += '\n';
- SysBreakFunc(debugStr);
- }
- else
- #endif
- {
- debugStr += ";g";
- DebugStr(debugStr);
- }
-
- byteCount -= len;
- }
- }
-
- #endif // qDebug || qTheDebugger
-
- //----------------------------------------------------------------------------------------
- // InstallWriteLnHook:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- #if qDebug || qTheDebugger
-
- void InstallWriteLnHook()
- {
- #if defined(__MWERKS__)
- InitCWDebug();
- #elif (THINK_CPLUS || SYMANTEC_CPLUS)
- // Don't have Symantec debug support yet
- #else
- fclose(stdin);
- fclose(stdout);
- fclose(stderr);
- const short _CODEV = 1; // console device number
- _addDevHandler(_CODEV, 0, DevFAccess, DevClose, DevRead, DevWrite, DevIoctl);
- freopen("dev:console", "r", stdin);
- freopen("dev:console", "a", stdout);
- freopen("dev:console", "a", stderr);
- SetPutProc(DebugWriteLnHook);
- setvbuf(stderr, NULL, _IOLBF, 128);
- SetGetProc(DebugReadLn);
- #endif
- }
-
- #endif // qDebug || qTheDebugger
-
- //----------------------------------------------------------------------------------------
- // End of UDebug.cp
-
- #pragma segment Inline
-